<%@ page import="ru.niir.goodfil.db.dic.OrderState" %>
<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Заказ</title>
    <link rel="stylesheet" type="text/css" href="resources/css/main.css"/>
    <link rel="stylesheet" type="text/css" href="resources/css/stylesheet.css"/>
    <link rel="stylesheet" type="text/css" href="resources/css/clients.css"/>
    <link rel="stylesheet" type="text/css" href="resources/css/simple_tables.css"/>
    <link rel="stylesheet" type="text/css" href="resources/css/jquery.countdown.css">
    <script type="text/javascript" src="resources/js/jquery.plugin.js"></script>
    <script type="text/javascript" src="resources/js/goodwill.js"></script>
    <script type="text/javascript" src="resources/js/prototype.js"></script>
    <script type="text/javascript" src="resources/js/shortcut.js"></script>
    <script type="text/javascript" src="resources/js/packageCount.js"></script>
    <script type="text/javascript" src="resources/js/jquery.countdown.js"></script>
    <script type="text/javascript">
        function reloadPage(){
            window.location.reload();
        }
    </script>
    <%--<script type="text/javascript">--%>
    <%--function deliveryInfoHasChanged()--%>
    <%--{--%>
    <%--new Ajax.Request('Order.updateDeliveryInfo.ajax',--%>
    <%--{--%>
    <%--method:'get',--%>
    <%--parameters: {--%>
    <%--deliveryType : $('sDeliveryType').value,--%>
    <%--bankType : $('sBankType').value,--%>
    <%--deliveryAddress : $('tbDeliveryAddress').value--%>
    <%--},--%>
    <%--onSuccess: function()--%>
    <%--{--%>
    <%--//                    alert('saved!');--%>
    <%--}--%>
    <%--});--%>
    <%--}--%>
    <%--;--%>
    <%--</script>--%>
    <script type="text/javascript">

        var addGoodModalPanelIsActive = 0;

        function init() {
            initShortcuts();
        }

        function selectTheGood(goodcode) {
            quickOrder_selectTheGood(goodcode);
        }

        function initShortcuts() {
            shortcut.add("Enter", function() {
                if (addGoodModalPanelIsActive) {
                    quickOrder_addGood();
                }
                else {
                    quickOrder_selectGood();
                }
            });

            shortcut.add("Home", function() {
                if (addGoodModalPanelIsActive) {
                    Richfaces.hideModalPanel('modalQuickOrder');
                    addGoodModalPanelIsActive = 0;
                }

                quickOrder_clear();
                Richfaces.showModalPanel('modalQuick');
                $('tbGoodCode').focus();
            });

            shortcut.add("Up", function() {
                quickOrder_up();
                $('tbGoodCode').focus();
            });

            shortcut.add("Down", function() {
                quickOrder_down();
                $('tbGoodCode').focus();
            });
        }

        function updateGoodsList() {
            quickOrder_updateGoodsList($('tbGoodCode').value);
        }

        function toggleSub(box, textId, inputId) {
            // get reference to related content to display/hide
            var textElem = document.getElementById(textId);
            var inputElem = document.getElementById(inputId);
            if ( box.checked ) {
                textElem.style.display = 'block';
                inputElem.style.display = 'block';
            } else {
                textElem.style.display = 'none';
                inputElem.value = "";
                inputElem.style.display = 'none';

            }
        }

        function setActualPrice(){
            if(confirm("Вы уверены, что хотите пересчитать цены на ВСЕ позиции заказа с учетом актуального прайса?")) actualPrice();
        }
    </script>
</head>
<body onload="init()">

<f:view>
<jsp:include page="menu.jsp"/>
<jsp:include page="orderClientInfo.jsp"/>
<jsp:include page="orderTopBar.jsp"/>
<jsp:include page="status.jsp"/>
<jsp:include page="messages.jsp"/>

<a4j:form prependId="false" id="jsForm">

    <h:inputHidden value="#{BlockExchangeBean.managerId}"/>
    <%--<a4j:jsFunction name="quickOrder_selectGood" action="#{OrderBean.quickOrder_selectGood}" reRender="dvQuickOrderGoods" oncomplete="$('tbGoodCode').focus(); if (#{OrderBean.quickOrder.goodsCount == 1}) { addGoodModalPanelIsActive = 1; Richfaces.showModalPanel('modalQuickOrder'); }"/>--%>

    <a4j:jsFunction name="quickOrder_selectGood" action="#{QuickOrderBean.selectGood}"
                    reRender="dvQuickOrderAddGood,dvQuickOrderAddError"
                    limitToList="true" ajaxSingle="true"
                    oncomplete="$('tbGoodCode').focus(); if (#{QuickOrderBean.current != null}) { addGoodModalPanelIsActive = 1; Richfaces.showModalPanel('modalQuickOrder'); }"/>

    <a4j:jsFunction name="quickOrder_selectTheGood" action="#{QuickOrderBean.selectTheGood}"
                    reRender="dvQuickOrderAddGood,dvQuickOrderAddError" limitToList="true" ajaxSingle="true"
                    oncomplete="$('tbGoodCode').focus(); if (#{QuickOrderBean.current != null}) { addGoodModalPanelIsActive = 1; Richfaces.showModalPanel('modalQuickOrder'); }">
        <a4j:actionparam name="goodCode" assignTo="#{QuickOrderBean.selectTheGoodCode}"/>
    </a4j:jsFunction>

    <a4j:jsFunction name="quickOrder_clear" action="#{QuickOrderBean.clear}" reRender="dvQuickOrderGoods"
                    limitToList="true" ajaxSingle="true"/>

    <a4j:jsFunction name="quickOrder_updateGoodsList" action="#{QuickOrderBean.updateGoodsList}"
                    reRender="dvQuickOrderGoods" eventsQueue="goodCode" requestDelay="100" status="a4j_status2"
                    limitToList="true" ajaxSingle="true">
        <a4j:actionparam name="goodCode" assignTo="#{QuickOrderBean.goodCode}"/>
    </a4j:jsFunction>

    <%--<a4j:jsFunction name="quickOrder_addGood"--%>
    <%--action="#{QuickOrderBean.addGood}"--%>
    <%--reRender="dvQuickOrderAddError"--%>
    <%--oncomplete="if (#{empty QuickOrderBean.lastError}) { addGoodModalPanelIsActive = 0; Richfaces.hideModalPanel('modalQuickOrder'); refreshOrderItems(); $('tbGoodCode').focus(); } else { $('hAddGoodCount').focus(); }"/>--%>

    <a4j:jsFunction name="refreshOrderItems" reRender="dvOrderItems"/>

    <a4j:jsFunction name="quickOrder_up" action="#{QuickOrderBean.up}" reRender="dvQuickOrderGoods" limitToList="true"
                    ajaxSingle="true" eventsQueue="goodCode" status="a4j_status2"/>
    <a4j:jsFunction name="quickOrder_down" action="#{QuickOrderBean.down}" reRender="dvQuickOrderGoods"
                    limitToList="true" ajaxSingle="true" eventsQueue="goodCode" status="a4j_status2"/>

    <a4j:jsFunction name="actualPrice" action="#{OrderBean.actualPriceForOrder}" limitToList="true" ajaxSingle="true"/>
</a4j:form>

<h:panelGroup layout="block" styleClass="" id="dvOrderHeader">
    <h:panelGrid columns="2" cellpadding="0" cellspacing="0" columnClasses="cgray,cwhite">
        <h:outputText value="Заказ #" styleClass="b"/>
        <h:outputText value="#{OrderBean.order.id}"/>
        <h:outputText value="Менеджер" styleClass="b"/>
        <h:outputText value="#{OrderBean.order.manager.fio}"/>
        <h:outputText value="Дата создания заказа" styleClass="b"/>
        <h:outputText value="#{OrderBean.order.creationDateAsString}"/>
        <h:outputText value="Статус заказа" styleClass="b"/>
        <h:outputText value="#{OrderBean.order.orderStateAsString}"/>
        <h:outputText value="1С" styleClass="b"/>
        <h:outputText value="#{OrderBean.order1CString}"/>
        <h:outputText value="Ответственный за сборку" rendered="#{OrderBean.order.orderStateIsComplete || OrderBean.order.orderStateIsOutput}" styleClass="b"/>
        <h:outputText value="#{OrderBean.order.storekeeper.fio}" rendered="#{OrderBean.order.orderStateIsComplete || OrderBean.order.orderStateIsOutput}"/>
    </h:panelGrid>
</h:panelGroup>

<h:panelGroup styleClass="" layout="block" style="margin-top:10px" id="dvOrderItems">

<h:panelGroup styleClass="" layout="block" rendered="#{not empty OrderBean.someItems}">
    <h:dataTable border="0" cellpadding="0" cellspacing="5" value="#{OrderBean.someItems}" var="someItem">
        <f:facet name="header">
            <h:outputText value="Из заказа были исключены позиции: "/>
        </f:facet>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Код"/>
            </f:facet>
            <h:outputText value="#{someItem.code}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Наименование"/>
            </f:facet>
            <h:outputText value="#{someItem.name}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Затребованное количество"/>
            </f:facet>
            <h:outputText value="#{someItem.requested}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Доступное количество"/>
            </f:facet>
            <h:outputText value="#{someItem.available}"/>
        </h:column>
    </h:dataTable>
</h:panelGroup>

<h:form id="Form">

    <h:panelGroup styleClass="" layout="block" style="background-color:whitesmoke;padding:4px;" id="dvActions">
        <h:outputText value="Действия: " styleClass="b"/>

        <h:panelGroup id="blockStarted" rendered="#{QuickOrderBean.block}">
                <h:outputText value="Блокировка установлена для #{QuickOrderBean.managerForBlock}" style="font-size: 1.2em;"/>
                <div id="defaultCountdown" style="width: 240px; height: 45px;"></div>
                <rich:jQuery selector="#defaultCountdown" query="countdown({until: +'#{BlockExchangeBean.sec}', format: 'yowdHMS', onExpiry: reloadPage})"/>
        </h:panelGroup>

        <h:panelGroup id="orderSuccess" rendered="#{QuickOrderBean.privelegeUser||!QuickOrderBean.block}">
        <a4j:commandLink action="#{OrderBean.validateOrder}"
                         rendered="#{OrderBean.canSendToStore}"
                         style="margin-left:10px" reRender="dvOrderMenu,dvOrderHeader,dvOrderItems,dvActions">
            <h:graphicImage value="/resources/img/docok_16.gif"/>
            <h:outputText value="отправить на склад"/>
        </a4j:commandLink>

        <h:panelGroup styleClass="" style="background-color:whitesmoke;padding:4px;" rendered="#{OrderBean.clientBlockRender}">
                <h:outputText value="Клиент заблокирован в 1С. Невозможно отправить заказ на склад." style="font-size: 14;"/>
        </h:panelGroup>

        <a4j:commandLink action="#{OrderBean.notValidateOrder}"
                         rendered="false"
                         style="margin-left:10px" reRender="dvOrderMenu,dvOrderHeader,dvOrderItems,dvActions">
            <h:graphicImage value="/resources/img/docclose_16.gif"/>
            <h:outputText value="не согласовать"/>
        </a4j:commandLink>

        <a4j:commandLink action="#{OrderBean.doSaveOrder}" rendered="#{OrderBean.orderStateIsPreSaved && not empty OrderBean.orderItemList}"
                         style="margin-left:10px" reRender="dvOrderMenu,dvOrderHeader,dvOrderItems,dvActions"
                         oncomplete="updateGoodsList();">
            <h:graphicImage value="/resources/img/docopen_16.gif"/>
            <h:outputText value="зарезервировать"/>
        </a4j:commandLink>

        <a4j:commandLink id = "orderCombineLink" value="Объединение заказов" rendered="#{OrderBean.canCombineOrders}"
                         onclick="Richfaces.showModalPanel('combineOrders')"
                         style="margin-left: 10px"/>

        <a4j:commandLink id="updatePrice" value="ОБНОВИТЬ ЦЕНЫ" onclick="setActualPrice();" rendered="#{OrderBean.canUpdatePrices}"
                         reRender="dvOrderMenu,dvOrderHeader,dvOrderItems,dvActions" style="margin-left: 10px"/>

            <a4j:outputPanel id="bildPanel" ajaxRendered="true">
                <a4j:commandLink value="ПОЛУЧИТЬ СЧЕТ НА ЗАКАЗ" action="#{OrderBean.orderCalculate}" style="margin-left: 10px"
                                 rendered="#{OrderBean.canGetBild}"/>
            </a4j:outputPanel>


        </h:panelGroup>

        <a4j:commandLink action="#{OrderBean.doRemoveSomeItems}" rendered="#{OrderBean.orderStateIsPreSaved && not empty OrderBean.orderItemList}"
                         style="margin-left:10px" reRender="dvOrderMenu,dvOrderHeader,dvOrderItems,dvActions">
            <h:outputText value="убрать недостающие позиции"/>
        </a4j:commandLink>

        <h:outputLink value="#" onclick="Richfaces.showModalPanel('modalQuick');" style="margin-left:10px"
                      rendered="#{OrderBean.orderIsEditableNew}">быстрый набор [Home]</h:outputLink>
        <h:outputLink value="#"
                      rendered="#{OrderBean.order.orderStateIsAwaitingDelivery ||
                                  OrderBean.order.orderStateIsOnDelivery ||
                                  OrderBean.order.orderStateIsOutput}"
                      style="margin-left:10px"
                      title="Изменить дату отгрузки"
                      onclick="Richfaces.showModalPanel('modalAwaitingDelivery');">
            <h:outputText value="Изменить дату отгрузки"/>
        </h:outputLink>

    </h:panelGroup>

    <rich:dataTable id="tblOrderItem"
                    value="#{OrderBean.orderItemList}"
                    var="orderItem"
                    rowKeyVar="row"
                    styleClass="full"
                    columnClasses="ordr_c0,ordr_c1,ordr_c2,ordr_c3,ordr_c4,ordr_c5,ordr_c6,ordr_c6,ordr_c7">
        <rich:column>
            <f:facet name="header">
                <h:outputText value="№"/>
            </f:facet>
            <h:outputText value="#{row + 1}. "/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Код"/>
            </f:facet>
            <h:outputText value="#{orderItem.good.code}" styleClass="b"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Наименование"/>
            </f:facet>
            <h:outputText value="#{orderItem.good.name}" styleClass="b"/>
        </rich:column>
        <%--<rich:column>--%>
        <%--<f:facet name="header">--%>
        <%--<h:outputText value="о.е."/>--%>
        <%--</f:facet>--%>
        <%--<h:outputLink value="#oe" onclick="showOesModalPanel('#{good.code}')">--%>
        <%--<h:outputText value="#{good.oeShort}" id="lOeShort"/>--%>
        <%--</h:outputLink>--%>
        <%--</rich:column>--%>
        <%--<rich:column>--%>
        <%--<f:facet name="header">--%>
        <%--<h:outputText value="Применимость"/>--%>
        <%--</f:facet>--%>
        <%--<h:outputText value="#{orderItem.good.pr}"/>--%>
        <%--</rich:column>--%>
        <rich:column>
            <f:facet name="header">
                <h:outputText value="Вес"/>
            </f:facet>
            <h:outputText value="#{orderItem.good.weight}" converter="VolumeConverter"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Объем"/>
            </f:facet>
            <h:outputText value="#{orderItem.good.volume}" converter="VolumeConverter"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Количество"/>
            </f:facet>
            <h:outputText value="#{orderItem.count} шт."/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Количество в гр.таре"/>
            </f:facet>
            <h:outputText value="#{orderItem.good.packageCount} шт."/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Цена"/>
            </f:facet>

            <h:outputText style="color:dimgray;font-size:80%" value=""
                          rendered="#{!(orderItem.personalPrice || orderItem.manualPrice != 0)}"/>
            <h:outputText style="color:dimgray;font-size:80%" value="(перс. цена)"
                          rendered="#{orderItem.personalPrice}"/>
            <h:outputText style="color:dimgray;font-size:80%" value="(вручную)"
                          rendered="#{orderItem.manualPrice != 0}"/>

            <rich:spacer width="20"/>

            <h:outputText value="#{orderItem.itemPrice} р."/>

        </rich:column>
        <rich:column>
            <f:facet name="header">
                <h:outputText value="Стоимость позиции"/>
            </f:facet>

            <h:outputText value="#{orderItem.sum} р."/>

        </rich:column>
        <rich:column>
            <h:panelGroup rendered="#{OrderBean.orderIsEditableNew}">
                <h:inputText id="orderItemCount"
                             value="#{OrderBean.orderItemsCount[orderItem.id]}"
                             required="true"
                             requiredMessage="Введите количество товара"
                             converterMessage="Количество товара должно быть числом"
                             style="width:35px"/>
                <h:outputText value="шт." style="padding-left:1px"/>

                <a4j:commandLink value="изменить" action="#{OrderBean.updateOrderItem}" reRender="orderItemCount,dvOrderItems"
                                 style="padding-left:5px">
                    <a4j:actionparam name="updeteOrderItem" assignTo="#{OrderBean.orderItem.id}"
                                     value="#{orderItem.id}"/>
                </a4j:commandLink>

                <a4j:commandLink value="удалить" action="#{OrderBean.deleteOrderItem}" reRender="dvOrderItems"
                                 style="padding-left:5px">
                    <a4j:actionparam name="deleteOrderItem" assignTo="#{OrderBean.orderItem.id}"
                                     value="#{orderItem.id}"/>
                </a4j:commandLink>

                <a4j:commandLink value="установить цену" onclick="#{rich:component('modalPrice')}.show();"
                                 style="padding-left:5px" rendered="#{SecurityBean.isRoleAdministrator}">
                    <a4j:actionparam name="orderItemId" assignTo="#{sessionScope['orderItemId']}"
                                     value="#{orderItem.id}"/>
                </a4j:commandLink>
            </h:panelGroup>
        </rich:column>
        <f:facet name="footer">
            <rich:columnGroup>
                <rich:column/>
                <rich:column/>

                <%-- Вес и объем --%>
                <rich:column>
                    <h:outputText value="Суммарный вес: #{OrderBean.orderWeight}"/><br>
                    <h:outputText value="Суммарный объем: #{OrderBean.orderVolume}"/>
                </rich:column>
                <rich:column/>
                <rich:column/>
                <%-- Количество --%>
                <rich:column style="text-align:right">
                    <h:outputText value="#{SessionBean.orderGoodsCount} шт." styleClass="b"/>
                </rich:column>
                <rich:column/>
                <rich:column/>
                <%-- Цена --%>
                <rich:column style="text-align:right">
                    <h:outputText value="Сумма: #{SessionBean.orderPrice + SessionBean.deliverySum} р." styleClass="b"
                                  id="lOrderSum"/>
                    <rich:toolTip for="lOrderSum">
                        <h:panelGrid columns="2" cellpadding="0" cellspacing="0" columnClasses="lsummary,rsummary"
                                     styleClass="summary">
                            <h:outputText value="Стоимость заказа"/>
                            <h:outputText value="#{SessionBean.orderPrice}"/>

                            <h:outputText value="Стоимость доставки"/>
                            <h:outputText value="#{SessionBean.deliverySum}"/>

                            <h:outputText value="ИТОГО"/>
                            <h:outputText value="#{SessionBean.total}"/>
                        </h:panelGrid>
                    </rich:toolTip>
                </rich:column>
                <rich:column/>
            </rich:columnGroup>

        </f:facet>
    </rich:dataTable>
</h:form>
</h:panelGroup>
<br>
<%-- Расширенная информация о доставке --%>
<h:panelGroup layout="block" styleClass="" style="margin-top:10px" id="dvOrderDeliveryInfoExt">
    <h:form id="fOrderDeliveryInfoExt" prependId="false">
        <h:panelGrid columns="2" cellpadding="0" cellspacing="10"
                     style="border:0;margin:0;background-color:whitesmoke;">
            <h:panelGroup styleClass="" layout="block" style="background-color:whitesmoke;padding:4px;" id="dvActions">
                <h:outputText value="Дополнительная информация" styleClass="b"/>
            </h:panelGroup>
            <rich:spacer/>
            <h:outputText value="Тип оплаты"/>
            <h:selectOneMenu value="#{OrderBean.order.deliveryInfoExt.payType}"
                             disabled="#{!OrderBean.firmAndPayTypeIsEditable}">
                <f:selectItem itemValue="#{true}" itemLabel="Нал. расчет"/>
                <f:selectItem itemValue="#{false}" itemLabel="Безн. расчет"/>
            </h:selectOneMenu>

            <h:outputText value="Фирма"/>
            <h:selectOneMenu value="#{OrderBean.order.firm}" id="sFirm" disabled="#{!OrderBean.firmAndPayTypeIsEditable}">
                <f:selectItem itemValue="#{0}" itemLabel="---"/>
                <f:selectItem itemValue="#{5}" itemLabel="Регор"/>
                <f:selectItem itemValue="#{6}" itemLabel="Регор бух."/>
                <f:selectItem itemValue="#{7}" itemLabel="Специнструмент"/>
                <f:selectItem itemValue="#{8}" itemLabel="Специнструмент бух."/>

            </h:selectOneMenu>

            <h:outputText value="Способ доставки"/>
            <h:selectOneMenu value="#{OrderBean.order.deliveryTypeId}" disabled="#{!OrderBean.orderDeliveryInfoIsEditable}">
                <f:selectItems value="#{OrderBean.deliveryTypesAsSelectItems}"/>
            </h:selectOneMenu>

            <h:outputText value="Транспортная компания" style="padding-left:20px;"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.transportName}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Контактное лицо транспортной компании" style="padding-left:20px;"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.transportContactFio}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Адрес транспортной компании" style="padding-left:20px;"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.transportAddress}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Телефон транспортной компании" style="padding-left:20px;"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.transportTel}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Адрес получателя" style="padding-left:20px;"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.targetAddress}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Контактное лицо получателя" style="padding-left:20px;"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.targetContactFio}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Телефон получателя" style="padding-left:20px;"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.targetTel}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Дата отгрузки"/>
            <rich:calendar value="#{OrderBean.order.deliveryDateAsJavaUtilDate}" locale="RU" datePattern="dd.MM.yyyy"
                           readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <h:outputText value="Срок резервирования"/>
            <rich:calendar value="#{OrderBean.order.reservationDateAsDate}" locale="RU" datePattern="dd.MM.yyyy"
                           readonly="#{!OrderBean.orderIsEditable}"/>

            <h:outputText id="add" value="Дополнительный заказ" title="Необходимо отметить, если данный заказ является дополнительным для уже существующего"/>
            <h:selectBooleanCheckbox id="checkbox" value="#{OrderBean.order.additional}" disabled="#{!OrderBean.orderIsEditable}"
                                     onclick="toggleSub(this, 'numLabel', 'numValue');"/>

                <h:outputText id="numLabel" value="Номер основного заказа (если доп.заказ)" style="display: none;"/>
                <h:inputText id="numValue" value="#{OrderBean.order.mainOrderId}"
                             requiredMessage="Для доп. заказа обязательно указывать номер основного заказа"
                             converterMessage="Поле \"Номер основного заказа\" должно быть числом"
                             style="display: none;">
                    <f:convertNumber integerOnly="true" type="number" />
                </h:inputText>


            <h:outputText value="Комментарий"/>
            <h:inputText value="#{OrderBean.order.deliveryInfoExt.comment}" style="width:400px"
                         readonly="#{!OrderBean.orderDeliveryInfoIsEditable}"/>

            <a4j:commandButton action="#{OrderBean.updateOrderDeliveryInfoExt}" value="Сохранить"
                               rendered="#{OrderBean.orderDeliveryInfoIsEditable}" reRender="bildPanel"/>
            <a4j:commandButton value="Выгрузить заказ в Excel" action="#{OrderBean.doOrderExport}" status="none"/>
            <%-- Эта штука НУЖНА, без нее календарик вылезает за границу экрана --%>
            <rich:spacer width="10px" height="200px"/>
        </h:panelGrid>
    </h:form>
</h:panelGroup>

<rich:modalPanel id="modalPrice" autosized="true" width="350">
    <f:facet name="header">
        <h:panelGroup>
            <h:outputText value="Установка цены"/>
        </h:panelGroup>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="/resources/img/close.png" styleClass="hidelink"
                        onclick="#{rich:component('modalPrice')}.hide();return false;"/>
    </f:facet>
    <h:form>
        <jsp:include page="messages.jsp"/>

        <h:outputText value="Укажите цену на позицию"/>
        <h:inputText value="#{OrderBean.manualPrice}" converterMessage="Цена должна быть числом"/>

        <br>

        <a4j:commandButton value="Применить" action="#{OrderBean.applyManualPrice}" reRender="dvOrderItems"
                           oncomplete="#{rich:component('modalPrice')}.hide();"/>
        <a4j:commandButton value="Сбросить" action="#{OrderBean.resetManualPrice}" reRender="dvOrderItems"
                           oncomplete="#{rich:component('modalPrice')}.hide();"/>
    </h:form>
</rich:modalPanel>

<rich:modalPanel id="modalQuick" width="350" height="500" onshow="$('tbGoodCode').focus()">
    <f:facet name="header">
        <h:panelGroup>
            <h:outputText value="Быстрый набор"/>
        </h:panelGroup>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="/resources/img/close.png" onclick="Richfaces.hideModalPanel('modalQuick');"/>
    </f:facet>
    <a4j:status forceId="true" id="a4j_status2"/>

    <h:outputText value="Код товара" style="font-size:140%"/>
    <h:inputText id="tbGoodCode" onkeyup="updateGoodsList();" style="font-size:140%;margin-left:20px"/><br>

    <h:panelGroup id="dvQuickOrderGoods" style="margin-top:20px">
        <a4j:repeat value="#{QuickOrderBean.goods}" var="good">
            <h:panelGroup rendered="#{good.selected}"
                          style="background-color:lightgreen;border:2px solid darkgreen;padding:2px;margin-top:2px;white-space:nowrap   ">
                <h:outputLink value="#" onclick="selectTheGood('#{good.code}')">
                    <h:outputText value="#{good.code}" styleClass="b" style="text-decoration:none;color:black"/>
                    <h:outputText value="#{good.name}" style="padding-left:5px;text-decoration:none;color:black"/>
                </h:outputLink>
                <br>
            </h:panelGroup>
            <h:panelGroup rendered="#{!good.selected}" style="padding:5px;margin-top:5px;white-space:nowrap">
                <h:outputLink value="#" onclick="selectTheGood('#{good.code}')">
                    <h:outputText value="#{good.code}" styleClass="b" style="text-decoration:none;color:black"/>
                    <h:outputText value="#{good.name}" style="padding-left:5px;text-decoration:none;color:black"/>
                </h:outputLink>
                <br/>
            </h:panelGroup>
        </a4j:repeat>
    </h:panelGroup>
</rich:modalPanel>

<rich:modalPanel id="modalQuickOrder" autosized="true" width="400" onshow="$('hAddGoodCount').focus()">
    <f:facet name="header">
        <h:panelGroup>
            <h:outputText value="Добавить в заказ"/>
        </h:panelGroup>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="/resources/img/close.png"
                        onclick="addGoodModalPanelIsActive = 0; Richfaces.hideModalPanel('modalQuickOrder'); $('tbGoodCode').focus();"/>
    </f:facet>
    <a4j:outputPanel ajaxRendered="true">

        <h:panelGroup id="dvQuickOrderAddError">
            <h:outputText value="#{QuickOrderBean.lastError}" style="color:red"/>
        </h:panelGroup>

        <a4j:form prependId="false">
            <a4j:jsFunction name="quickOrder_addGood"
                            action="#{QuickOrderBean.addGood}"
                            reRender="dvQuickOrderAddError"
                            oncomplete="if (#{empty QuickOrderBean.lastError}) { addGoodModalPanelIsActive = 0; Richfaces.hideModalPanel('modalQuickOrder'); refreshOrderItems(); $('tbGoodCode').focus(); } else { $('hAddGoodCount').focus(); }"/>
            <h:panelGrid cellpadding="0" cellspacing="0" columns="2" columnClasses="dleft,dright"
                         id="dvQuickOrderAddGood">
                <h:outputText value="Наименование товара" styleClass="b"/>
                <h:outputText value="#{QuickOrderBean.current.goodName}"/>
                <h:outputText value="Код товара" styleClass="b"/>
                <h:outputText value="#{QuickOrderBean.current.goodCode}"/>
                <h:outputText value="Количество в гр. таре" styleClass="b"/>
                <h:outputText value="#{QuickOrderBean.current.packageCount}"/>
                <h:outputText value="Доступно" styleClass="b"/>
                <h:outputText value="#{QuickOrderBean.current.free}"/>
                <h:outputText value="Количество" styleClass="b"/>
                <h:inputText value="#{QuickOrderBean.current.count}" id="hAddGoodCount" tabindex="10"
                             style="width:50px" onkeyup="takeAddGoodCurrentValue(#{QuickOrderBean.current.packageCount})" onkeypress="takeAddGoodCurrentValue(#{QuickOrderBean.current.packageCount})"/>
                <h:outputText value="По-прейскуранту" styleClass="b"/>
                <h:outputText value="#{QuickOrderBean.current.firstprice}"/>
                <h:outputText value="Цена" styleClass="b"/>
                <h:inputText value="#{QuickOrderBean.current.price}" id="hAddGoodPrice" tabindex="11"
                             style="width:50px"/>
                <h:outputText value="Кратность гр.таре" styleClass="b"/>
                <span id="multiplenesPackageCount"></span>
            </h:panelGrid>
        </a4j:form>

        <h:panelGrid columns="2" cellpadding="5" cellspacing="5" style="margin-top:10px">
            <h:graphicImage value="/resources/img/info.png"/>
            <h:panelGroup>
                <h:outputText value="Чтобы добавить товар в заказ введите кол-во и нажмите <b>\"Enter\"</b>. "
                              escape="false"
                              style="font-size:9pt"/>
                <h:outputText value="Чтобы закрыть это окно нажмите <b>\"Home\"</b>. " escape="false"
                              style="font-size:9pt"/>
            </h:panelGroup>
        </h:panelGrid>

    </a4j:outputPanel>
</rich:modalPanel>

<%--
Модальное окно для задания даты отгрузки после сборки предоплатного заказа на складе
--%>
<rich:modalPanel id="modalAwaitingDelivery" autosized="true" width="400">
    <a4j:form>
        <h:panelGrid columns="2">
            <h:outputText value="Укажите дату отгрузки: "/>
            <rich:calendar id="calAwaitingDeliveryDate"
                           value="#{OrderBean.awaitingDeliveryDate}"
                           locale="RU"
                           datePattern="dd.MM.yyyy"/>
            <h:outputText value=" "/>
            <rich:message for="calAwaitingDeliveryDate" errorLabelClass="error" infoLabelClass="info"/>
        </h:panelGrid>

        <h:panelGrid columns="2" cellpadding="10">
            <a4j:commandButton value="Сохранить"
                               action="#{OrderBean.awaitingDeliveryAction}"
                               oncomplete="go('orders')"
                               />
            <a4j:commandButton value="Закрыть" immediate="true"
                               onclick="Richfaces.hideModalPanel('modalAwaitingDelivery');return false;"/>
        </h:panelGrid>
    </a4j:form>
</rich:modalPanel>

<rich:modalPanel id="combineOrders" autosized="true" width="400">
    <a4j:form>
            <h:outputText value="Объединить с "/>

            <h:selectOneMenu id = "ordersForCombine" value="#{OrderBean.orderForCombineId}">
                <t:selectItems value="#{OrderBean.ordersForCombine}" var="order" itemLabel="#{order.id}" itemValue="#{order.id}"/>
            </h:selectOneMenu>
        <h:panelGrid columns="2" cellpadding="10">
            <a4j:commandButton value="Объединить" action="#{OrderBean.combineOrders}" reRender="tblOrderItem, ordersForCombine, Form"
                               oncomplete="Richfaces.hideModalPanel('combineOrders'); return false;" />
            <a4j:commandButton value="Закрыть" immediate="true"
                               onclick="Richfaces.hideModalPanel('combineOrders');return false;"/>
        </h:panelGrid>
    </a4j:form>
</rich:modalPanel>

<%--<jsp:include page="oes.jsp"/>--%>
</f:view>

</body>
</html>